class Cpanel::JobsController < Cpanel::BaseController

  before_filter :find_job, only: [:show, :edit, :update, :destroy]

  def index
    @jobs = Job.by_created_at_desc.paginate(page: params[:page])
  end

  def show
  end

  def new
    @job = Job.new
  end

  def create
    @job = Job.new job_params

    if @job.save
      redirect_to [:cpanel, @job], notice: 'created success'
    else
      flash[:notice] = "created failed"
      render 'new'
    end
  end

  def edit
  end

  def update
    if @job.update_attributes job_params
      redirect_to [:cpanel, @job], notice: 'updated success'
    else
      flash[:notice] = "updated failed"
      render 'edit'
    end
  end

  def destroy
    @job.destroy
    redirect_to cpanel_jobs_path, notice: 'delete success'
  end


  private

  def find_job
    @job = Job.find(params[:id])
  end

  def job_params
    params.require(:job).permit(:position, :location, :num, :content, :language)
  end
end
